#include<iostream>
#include<string>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 1e4 + 10;
int a[N];
int n, m;
int main()
{
	int t;
	cin >> t;
	while (t--) {
		cin >> n >> m;
		memset(a, 0, sizeof(a));
		for (int i = 0; i < n * m; i++) {
			cin >> a[i];
		}
		sort(a, a + n * m);
		//int ans1 = 0;//С
		//int ans2 = 0;
		//for (int i = 1; i < n; i++) {
		//	ans1 += a[i];
		//}
		//for (int i = n * m - 2; i >= n * m - n; i--) {
		//	ans2 += a[i];
		//}
		
		int f = a[n * m - 1];
		int s1 = a[1];
		int l = a[0];
		int s2 = a[n * m - 2];
		//cout << "ans1==" << f - s1 << endl;
		//cout << "ans2==" << s2 - l << endl;
		//cout << "ans===" << n * m - min(n, m) << endl;
		if (f - s1 >= s2 - l) {
			cout << (f - l) * (n * m - min(n,m)) + (f - s1) * (min(n,m)-1) << endl;
		}
		else {
			cout << (f - l) * (n * m - min(n,m)) + (s2 - l) *(min(n, m) - 1) << endl;
		}
		//cout << "f==" << f << endl;
		//cout << "s==" << s << endl;
		//cout << "l==" << l << endl;
		//cout << "-------=="<<(f - l) * (n * m - 1) << endl;
	}
	return 0;
}